/*
 * Copyright (c)  2015~2020, xforceplus
 * All rights reserved.
 * Project:datacare-orm
 * Id: Params.java   2020-09-29 23-42-00
 * Author: Evan
 */
package cn.datacare.orm.source;

import java.util.HashMap;
import java.util.Map;

import static cn.datacare.orm.constant.Constants.PARAM_ROOT;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Copyright: 2015~2020
 * </p>
 * <p>
 * Company/Department: xforceplus
 * </p>
 *
 * @author Evan
 * <b>Creation Time:</b> 2020-09-29 23-42-00
 * @since V1.0
 */
public class Params {
    /***
     * 参数集合
     */
    private Map<String,Object> map;


    /***
     * 构建Map对象
     * @param map
     */
    private Params(Map<String,Object> map){
        this.map=map;
    }

    /***
     * 创建实例
     * @return Params
     */
    public static Params ins(){
        return  Params.builder().build();
    }

    /**
     * 创建实例
     * @param value
     * @return  Params
     */
    public static Params ins(Object value){
        return  Params.builder().main(value).build();
    }

    /**
     * 添加参数
     * @param key Key
     * @param value Value
     * @return Params
     */
    public Params add(String key,String value){
        this.map.put(key,value);
        return this;
    }

    public Map<String, Object> map(){
        return this.map;
    }

    public static Builder builder(){
        return new Builder();
    }


    public static class  Builder{

        /***
         * 参数集合
         */
        private Map<String,Object> map;

        private Builder(){

            map=new HashMap<>();
        }

        private Builder add(String key,Object value){
            this.map.put(key,value);
            return  this;
        }

        public Builder main(Object value){
            this.map.put(PARAM_ROOT,value);
            return this;
        }

        public Params build(){
            return  new Params(this.map);
        }
    }
}
